from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.
class User(AbstractUser):
    username = models.CharField(max_length=150, unique=True)
    password = models.CharField(max_length=128)
    occupation = models.CharField(max_length=100, null=True)  # 职业
    native_place = models.CharField(max_length=200, null=True)  # 籍贯
    phone = models.CharField(max_length=20, null=True)  # 电话
    email = models.EmailField(blank=True, null=True)  # 邮箱
    description = models.TextField(blank=True, null=True)
    



    def __str__(self):
        return f"{self.__class__.__name__}"

class Category(models.Model):
    name = models.CharField(max_length=100, unique=True)

    def __str__(self):
        return f"{self.__class__.__name__}"


class Image(models.Model):
    image_file = models.ImageField()
    caption = models.CharField(max_length=200, null=True, blank=True)

    def __str__(self):
        return f"{self.__class__.__name__}"


class Article(models.Model):
    title = models.CharField(max_length=200)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    cate_id = models.ForeignKey(Category, on_delete=models.CASCADE)
    content = models.TextField()
    publish_time = models.DateTimeField(auto_now_add=True)
    images = models.ManyToManyField(Image)

    def __str__(self):
        return f"{self.__class__.__name__}"


class Album(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField()
    images = models.ManyToManyField(Image)

    def __str__(self):
        return f"{self.__class__.__name__}"